<%@ page contentType="text/html" pageEncoding="UTF-8" import="com.almori.hr.timetracker.*" import="java.io.File" import="java.util.*" import="java.sql.*" import="java.text.*" import="java.text.*" %>


<%
    try {
        MgrDashBean mb = new MgrDashBean();
        TimeTrackerBean bean = new TimeTrackerBean();
        Employee me = (Employee) session.getAttribute("Employee");

        if (me.getRole() == 2) {
            File f = new File(getServletContext().getRealPath("") + "\\img\\pics\\" + me.getPic());
            String p = (f.exists()) ? me.getPic() : "auser.jpg";  // check for pic or get generic one
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>Timetracker Almori BPO Services - Edit Timecards</title>
        <link rel="Shortcut icon" href="img/logo.png" />
        <link rel="stylesheet" type="text/css" href="css/style_mgr.css" />
        <!--[if IE 8]>
         <link rel="stylesheet" type="text/css" href="css/style_mrIE.css" />
      <![endif]-->
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script language="javascript" type="text/javascript">
            <!--
            function popitup(url) {
                newwindow = window.open(url, 'name', 'toolbar=yes, location=yes, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=470, height=420');
                if (window.focus) {
                    newwindow.focus()
                }
                return false;
            }


            // -->
        </script>
    </head>
    <body>
        <br />
        <div class="container">
            <div id="signup">
                <div class="top_left">
                    <img src="img/company.logo.19.jpg" alt="company logo"></img>
                </div>
                <div class="small_user_pic">
                    <a href="punchit.jsp"><img src="img/pics/<%= p%>" alt="pic" height="33" width="33"></img></a>
                    <a href="index.jsp"><img src="img/log-out.png" alt="sign out" height="33" width="33" ></img></a>
                </div>

                <div class="header">
                    <img src="img/logo.png" alt="logo"></img>
                </div> 

                <div align="center">
                    <h2>REVISAR ESTADOS</h2>
                </div>

                <div class="inputs">

                    <div id="boxed-center">
                        <form action="#" method="GET">
                            <div class="inputs">
                                <%

                                    String D = request.getParameter("dept");
                                    if (D == null || D.equals("")) { //First time in load %> 
                                <label float="left">Seleccione el Departamento: </label>
                                <select name="dept" id="combo" style=" width:300px; border: 1px solid #737b8d;text-align:center;" onChange="location = this.options[this.selectedIndex].value;"><br />
                                    <option></option>
                                    <%

                                        List<Department> departments = new ArrayList();
                                        departments = bean.getDepartmentsList();
                                        try {
                                            for (int i = 0; i < departments.size(); i++) {
                                                out.println("<option value='?dept=" + departments.get(i).getId() + "'>" + departments.get(i).getDescription() + "</option>");

                                            }

                                        } catch (Exception e) {
                                            out.println("<option value='0'>Error: cannot access DataBase!</option>");
                                        }
                                    %> 

                                </select>
                                <br /><br />
                                <%        }%>
                                <div id="employees">
                                    <style type="text/css">
                                        #editTable {
                                            border: 2px solid #CCCCCC;
                                            border-collapse: collapse;
                                            width: 700px; 
                                            font-family: Cambria, Cochin, Georgia, serif;
                                            font-size: 14px;
                                            margin-left: auto;
                                            margin-right: auto;
                                        }
                                        #editTable td, #editTable th {
                                            border: 1px solid #CCC;
                                            padding: 10px;
                                        }

                                        #editTable th:nth-of-type(2) {
                                            text-align: center;
                                        }

                                        #editTable td:nth-of-type(1), #editTable th:nth-of-type(1) {
                                            width: 85px; 
                                            text-align: center;
                                        }

                                        #editTable th {
                                            font-weight: bold;
                                            font-size: 16px;
                                            /*          background-color: #DDE9FF;*/
                                            background:#1BB7DF;
                                            color:#FFFFFF
                                        }

                                        #editTable tr:nth-of-type(2n + 2) {
                                            background-color: #ECF7FF;
                                        }

                                        #editTable tr:nth-of-type(2n + 3) {
                                            background-color: #FBFDFF;
                                        }
                                    </style>     





                                    <%

                                        try {
                                            if (D != null) {
                                                int depid = Integer.parseInt(D);
                                                //populate table with Employees
                                                List<Employee> employees = new ArrayList();
                                                employees = bean.getEmployeeListByDept(depid);
                                    %>
                                    <table id="editTable">
                                        <tr>
                                            <th>Nombre</th>
                                            <th>Estatus en Ficha</th>
                                            <th>Estatus de cuenta</th>

                                        </tr>   

                                        <%
                                                    if (employees != null && employees.size() > 0) {

                                                        for (int i = 0; i < employees.size(); i++) {
                                                            out.println("<tr>");

                                                            out.println("<td style=\"text-align: center;\"><a onclick=\"return popitup('accountunlock.jsp?id=" + employees.get(i).getId() + "')\" href=\"accountunlock.jsp?id=" + employees.get(i).getId() + "\">" + employees.get(i).getlName() + "," + employees.get(i).getfName() + "</a></td>");

                                                            // out.print(timecards.get(i).getId() + " - ");
                                                            if (employees.get(i).getStatus() != null) {
                                                                if (employees.get(i).getStatus() == "IN") {
                                                                    out.print("<td style=\"text-align: center;\">En Sistema </td> ");
                                                                } else {
                                                                    out.print("<td style=\"text-align: center;\">Fuera de Sistema </td> ");
                                                                }

                                                            } else {
                                                                out.print("<td></td>");
                                                            }
                                                            if (employees.get(i).getLock() == 0) {
                                                                out.print("<td style=\"text-align: center;\">Estatus Normal </td> ");
                                                            } else {
                                                                out.print("<td style=\"text-align: center;\">Estatus a Revisar </td> ");
                                                            }
                                                            out.println("</tr>");
                                                        }

                                                    } else {
                                                        // No results
                                                    }

                                                    out.println("<a href='unlock.jsp' style='float: left; font-size:12px;'> << Escojer nuevamente el departamento</a>");
                                                    out.println("<br /><br />");

                                                } else {
                                                }

                                            } catch (Exception e) {
                                            }
                                        %>

                                        <tr>
                                            <td width="20"></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </table>

                                    <br /><br />

                                </div>


                            </div>
                        </form>
                        <div id="results">



                        </div>


                    </div>

                    <div id="fix"><br /> </div>   
                </div>

            </div>
        </div>
    </body>
</html>
<%            } else {
            response.sendRedirect("punchit.jsp?last=mgrdash"); // Employee without MGR Privileges
            return;
        }
    } catch (Exception e) {
        //response.sendRedirect("index.jsp?error=1&last=mgrdash"); // Anything goes bad, get credentials once again
        return;
    }
%>